package projet.item;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

import projet.CustomException;
import projet.Tools;
import projet.dataaccess.DataAccess;
import projet.dataaccess.PathErrorException;

/**
 * The Photo class represents a Photo object. Information about the Photo is
 * stored and can be retrieved. We assume that we only deal with movie Photos at
 * this stage.
 * 
 * @author BRUN Sylvain
 * @version Janvier 27, 2010
 */
public class Photo extends Item {
	private String photographe;
	private String date;

	/**
	 * @param id
	 * @throws CustomException
	 */
	public Photo(int id) throws CustomException {
		super();
		this.id = id;
		this.AskEdit();
	}

	/**
	 * @param id
	 * @param theTitle
	 * @param comment
	 * @param photographe
	 * @param path
	 */
	public Photo(int id, String theTitle, String comment, String photographe,
			String date, String path) {
		super(id, theTitle, comment, path);
		this.photographe = photographe;
		this.date = date;
	}

	/**
	 * @param dataAccess
	 * @throws PathErrorException
	 */
	public Photo(DataAccess dataAccess) throws PathErrorException {
		super(dataAccess);
		this.photographe = dataAccess.getElementString("photographe");
		this.date = dataAccess.getElementString("date");
	}

	/*
	 * (non-Javadoc)
	 * @see Item#AskEdit()
	 */
	@Override
	public void AskEdit() throws CustomException {
		super.AskEdit();

		// photographe
		System.out.print("- Artist: ");
		this.photographe = Tools.readLineEdit(this.photographe);

		// Date
		System.out.print("- Date: ");
		this.date = Tools.readLineEdit(this.date);

	}

	/**
	 * @return The photographe for this photo.
	 */
	public String getPhotographe() {
		return this.photographe;
	}

	/**
	 * @return The date for this photo.
	 */
	public String getDate() {
		return this.date;
	}

	/*
	 * (non-Javadoc)
	 * @see projet.item.Item#play()
	 */
	@Override
	public void play() {
		if (Desktop.isDesktopSupported()) {
			if (Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
				try {
					Desktop.getDesktop().open(new File(path));
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}

	}

	/*
	 * (non-Javadoc)
	 * @see projet.item.Item#toMediaAccess()
	 */
	public DataAccess toMediaAccess() throws PathErrorException {
		DataAccess dataAccess = super.toMediaAccess();
		dataAccess.addElement("date", this.date);
		dataAccess.addElement("path", this.path);
		dataAccess.addElement("photographe", this.photographe);

		return dataAccess;
	}

	/**
	 * Méthode affichage pour un show
	 */
	public void affichage() {
		super.affichage();
		Tools.print(2, "Photograph  : " + this.photographe);
		Tools.print(2, "Date        : " + this.date);
	}

	/*
	 * (non-Javadoc)
	 * @see Item#toString()
	 */
	@Override
	public String toString() {
		return super.toString() + "Photographe:\"" + this.photographe
				+ "\" Date \"" + this.date;
	}

}
